//
//  WTVisitorController.swift
//  WTSinaWeibo
//
//  Created by  Wellim on 16/6/25.
//  Copyright © 2016年  Wellim. All rights reserved.
//

import UIKit

class WTVisitorController: UITableViewController {
     // 标识用户是否登录
    let isLogin: Bool = WTUserAccountTools.sharedUserAccountTools.isLogin
     // 访客视图对象(延迟创建 在我们需要的时候创建)
    var visitorView: WTVisitorView?
    
    override func loadView() {
        //代表登录
        if isLogin {
            
            super.loadView()
        }else{
         
          //代表用户没有登录
            setUpNav()
            
            setUpVisitorView()
            
            
        
        }
        
        
    }
    
    // MARK: - 设置访客视图
    private func setUpVisitorView (){
    
        
        
     visitorView = WTVisitorView()
        
        //实现闭包
        visitorView?.closure = {[weak self] in
            
          self?.loginClick()
        }
        
        
      view = visitorView
    

    }

    // MARK: - 设置导航栏
    private func setUpNav(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("loginClick"))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(WTVisitorController.loginClick))
    }
    
    
    // MARK: - 监听方法
    @objc private func loginClick(){
        
        let oauthVc = WTOAuthViewController()
        
        let navVc = UINavigationController(rootViewController: oauthVc)
        
        
         presentViewController(navVc, animated: true, completion: nil)
    
        
    }

    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
        
        
    }



    


}
